//////////////////////////////

Dim alfabeto(100) As String
Dim c As Integer
Dim palabras(5) As String
Dim pos As Integer

Private Sub Command1_Click()

End Sub

Private Sub Form_Load()

If txtarchivo.Text = Empity Then
mnulexico.Enabled = False
mnusin.Enabled = False
mnuguardar.Enabled = False
mnumod.Visible = False
End If


End Sub

Private Sub mnuabrir_Click()
txtarchivo.Visible = True
Label1.Visible = True

On Error GoTo ManipularErrorAbrir
CommonDialog1.Filter = "ficheros de texto(*.txt;doc)|"
CommonDialog1.FilterIndex = 1
CommonDialog1.ShowOpen

Dim NumFichero As Integer
NumFichero = FreeFile
Open CommonDialog1.FileTitle For Input As NumFichero
Label1.Caption = CommonDialog1.FileTitle

txtarchivo.Text = Input(LOF(1), #NumFichero)

SalirAbrir:
Close NumFichero
Exit Sub

ManipularErrorAbrir:
MsgBox Err.Description
Resume SalirAbrir
End Sub

Private Sub mnuayuda_Click()
Unload Me
Form3.Show
End Sub

Private Sub mnuguardar_Click()

On Error GoTo ManipularErrorGuardar
CommonDialog2.CancelError = True

CommonDialog2.Filter = "ficheros de texto(*.txt;*.doc)|" & _
                        "todos los archivos (*.*)|*.*"
CommonDialog2.FilterIndex = 1
CommonDialog2.ShowSave
Label1.Caption = CommonDialog2.FileTitle

Dim NumFichero As Integer
NumFichero = FreeFile
Open CommonDialog2.FileName For Output As NumFichero
Print #NumFichero, Form1!txtarchivo.Text

SalirGuardar:
Close NumFichero
Exit Sub

ManipularErrorGuardar:
If Err.Number = cdlCancel Then Exit Sub
MsgBox Err.Description
Resume SalirGuardar
End Sub

Private Sub mnuinfo_Click()
Form2.Show

End Sub

Private Sub mnulexico_Click()

txtarchivo.Enabled = False
tam_arch = Len(txtarchivo.Text)

'Esta seccion imprime en lista los caracteres permitidos
'a-z, A-Z, 0-9, =, ;,[, ], {, }, _,( ,) ,* ,- ,+ ,/ ,. , coma
c = 42

For i = 0 To 67
alfabeto(i) = Chr(c)

c = c + 1

If c = 58 Then
c = 65
End If

If c = 91 Then
c = 97
End If
List1.List(i) = alfabeto(i)
Next i
 

alfabeto(68) = "="
List1.List(68) = alfabeto(68)
alfabeto(69) = "["
List1.List(69) = alfabeto(69)
alfabeto(70) = "]"
List1.List(70) = alfabeto(70)
alfabeto(71) = "_"
List1.List(71) = alfabeto(71)
alfabeto(72) = "{"
List1.List(72) = alfabeto(72)
alfabeto(73) = "}"
List1.List(73) = alfabeto(73)
alfabeto(74) = "("
List1.List(74) = alfabeto(74)
alfabeto(75) = ")"
List1.List(75) = alfabeto(75)
alfabeto(76) = Chr(13)
alfabeto(77) = " "
alfabeto(78) = ";"
alfabeto(79) = Chr(34)


' Hasta esta parte acaba la impresion en lista

'Comienzo del Analisis Lexico
txterror.Text = ""
nc = 0

enter = vbNewLine
lin = 1
nerrores = 0
For ii = 1 To tam_arch
''''''''''''''''''''''''''''''''''''''''''

'Cuenta lineas
ele = Mid$(txtarchivo.Text, ii, 1)


'Verifica caracter por caracter
If ele = Chr(13) Then  'Chr(13)
lin = lin + 1
ii = ii + 1 'Para brincarse los comienzos de lnea
End If

band = False

'Verifica si el caracter analizado coincide en el alfabeto
For i = 0 To 79
If ele = alfabeto(i) Then
band = True
End If
Next i

'En caso de no encontrarse en el alfabeto la bandera seguira siendo
'falsa y se contabilizara un error y se devolvera la posicion del error
'y en que letra sucedio

If band = False Then
nerrores = nerrores + 1
nc = nc + 1
txterror.Visible = True
Label2.Visible = True
txterror.Text = txterror.Text + " error " & nc & ": " & ele & "..........Linea " & lin & vbNewLine

End If
Next ii

'Para Devolver el Mensaje de Analisis Correcto
If nerrores = 0 Then
txterror.Visible = True
Label2.Visible = True
txterror.Text = "Anlisis de Lxico Correcto"
End If

'CONDICION PARA EVALUAR SI NO HAY DATOS INTRODUCIDOS
If txtarchivo.Text = "" Or txtarchivo.Text = Empity Then
txterror.Text = "No se pudo efectuar el Analisis Lxico "
mensaje = MsgBox("No hay expresiones a evaluar", vbCritical, "Error")
txterror.Visible = False
Label2.Visible = False
txtarchivo.Enabled = True
txtarchivo.SetFocus
End If

'Condicion para poder activar el Menu de Analizador Sintactico
If nerrores = 0 And txtarchivo.Text <> Empity Then
mnusin.Enabled = True
End If



' Para poder corregir los errores que llegasen a originar durante el analisis Lexico
If nerrores > 0 Then
aviso = MsgBox("Existen caracteres invalidos en las expresiones", vbCritical, "Error")
correccion = MsgBox("Desea depurarlos?", vbYesNo, "Correccion")
    If correccion = vbYes Then
    txtarchivo.Enabled = True
    txtarchivo.SetFocus
    End If
End If


' Activacion de Modificacion del txtarchivo
If txtarchivo.Text <> Empity Then
mnumod.Visible = True
End If

End Sub



Private Sub mnumod_Click()
txtarchivo.Enabled = True
txtarchivo.SetFocus
End Sub

Private Sub mnunuevo_Click()

txtarchivo.Visible = True
txtarchivo.Enabled = True
Label1.Visible = True
txtarchivo.Text = ""
txterror.Text = ""
txterror.Visible = False
Label2.Visible = False
mnulexico.Enabled = True
mnusin.Enabled = False
mnuguardar.Enabled = True
mnumod.Visible = False

End Sub

Private Sub mnusalir_Click()
Unload Me
End
End Sub

                   
Private Sub mnusin_Click()


List2.Clear
List3.Clear
List4.Clear
List5.Clear
List6.Clear
List7.Clear
List8.Clear
List9.Clear
List10.Clear
txterror.Text = ""
txtarchivo.Enabled = False

palabras(0) = "int"
palabras(1) = "float"
palabras(2) = "char"
palabras(3) = "String"
palabras(4) = "double"
tam = Len(txtarchivo.Text)

Dim tok(1000) As String
Dim pos(1000) As Integer

lin = 1
n = 0
' particion en tokens
' partiendo las cadenas en caracteres
For i = 1 To tam + 1
    car = Mid$(txtarchivo.Text, i, 1)

    'OOOOOOOOOOO
        
        If (car = "") Or (car = "=") Or (car = " ") Or (car = ";") Or (car = Chr(13)) Or (i = tam + 1) Or (car = ",") Or (car = "+") Or (car = "-") Or (car = "*") Or (car = "/") Or (car = "(") Or (car = ")") Then


        List2.List(n) = tok(n)
        pos(n) = lin
        List3.List(n) = pos(n)
        n = n + 1

        'tok(n) = tok(n) & Mid$(txtarchivo.Text, i, 1)
        If car = ";" Then
            tok(n) = ";"
            List2.List(n) = tok(n)
            pos(n) = lin
            List3.List(n) = pos(n)
            n = n + 1
        End If
        
        ' Analisis de caracteres matematicos
        If (car = "+") Or (car = "-") Or (car = "*") Or (car = "/") Or car = "(" Or car = ")" Then
            tok(n) = car
            List2.List(n) = tok(n)
            pos(n) = lin
                     List3.List(n) = pos(n)
            n = n + 1
        End If

        If car = "=" Then
            tok(n) = "="
            List2.List(n) = tok(n)
            pos(n) = lin
            List3.List(n) = pos(n)
            n = n + 1
        End If


        If car = "," Then
            tok(n) = ","
            List2.List(n) = tok(n)
            pos(n) = lin
            List3.List(n) = pos(n)
            n = n + 1
        End If

        If car = " " Then
            tok(n) = " "
            List2.List(n) = tok(n)
            pos(n) = lin
            List3.List(n) = pos(n)
            n = n + 1
        End If

        If car = Chr(34) Then
            tok(n) = Chr(34)
            List2.List(n) = tok(n)
            pos(n) = lin
            List3.List(n) = pos(n)
            n = n + 1
        End If

    
    
    '0000000000000
    
    
    Else
    ' concatenacion de tokens
        tok(n) = tok(n) & car
    End If

    If car = Chr(13) Then
        lin = lin + 1
        i = i + 1 'Para brincarse los comienzos de lnea
    End If
Next i

'para llenar la lista 10 apartir de la lista 2(sin espacios en blanco)
h = 0
g = 0



For g = 0 To List2.ListCount - 1
    If List2.List(g) <> "" And List2.List(g) <> " " Then
        List10.List(h) = List2.List(g)
        h = h + 1
    End If
Next g


'''''''''''''''''''''''''''''

 h = 0
For i = 0 To List2.ListCount
If (List2.List(i) <> "") And (List2.List(i) <> " ") Then
List11.List(h) = List2.List(i)
h = h + 1
Else
End If
Next i



'''''''''''''''''''''''''''''''

Dim ainteger(100) As String
Dim afloat(100) As String
Dim achar(100) As String
Dim astring(100) As String
Dim adouble(100) As String

u = 0
v = 0
q = 0
z = 0
Y = 0
csimple = False
cdoble = False



For i = 0 To List10.ListCount - 1
inicio:

        w = Mid$(List10.List(i), 1, 1)
        If w = Chr(39) Then
        csimple = True
        End If
        
       
       
        ww = Mid$(List10.List(i), 1, 1)
        If ww = Chr(34) Then
        cdoble = True
        End If



    Select Case List10.List(i)

        'PRIMER CASO ENTEROS

        Case "int":
            
inicio2:
            i = i + 1
            Var = iden(List10.List(i))
            If (Var = True) Then
                i = i + 1
                If List10.List(i) = ";" Then
                    ainteger(u) = List10.List(i - 1)
                    List4.List(u) = ainteger(u)
                    u = u + 1
                    GoTo inicio
                End If
                If List10.List(i) = "=" Then
                    i = i + 1
                    If IsNumeric(List10.List(i)) Then
                        i = i + 1
                        If List10.List(i) = ";" Then
                            ainteger(u) = List10.List(i - 3)
                            List4.List(u) = ainteger(u)
                            u = u + 1
                            GoTo inicio
                        Else
                            If List10.List(i) = "," Then
                                ainteger(u) = List10.List(i - 3)
                                List4.List(u) = ainteger(u)
                                u = u + 1
                                GoTo inicio2
                            End If
                        End If
                    Else

                        Label2.Visible = True
                        txterror.Visible = True
                        txterror.Text = txterror.Text + vbctrf + "Error, Lnea" & List3.List(i) & "Tipo asignado incorrecto" & List10.List(i) + vbNewLine

                    End If
                End If
                If List10.List(i) = "," Then
                    ainteger(u) = List10.List(i - 1)
                    List4.List(u) = ainteger(u)
                    u = u + 1
                    GoTo inicio2
                Else
                    Label2.Visible = True
                    txterror.Visible = True
                    txterror.Text = txterror.Text + vbctrf + "Error, Lnea" & List3.List(i) & "Error de sintaxis" & List10.List(i) + vbNewLine
                    'correccion de errores en el analisis sintactico por parte del usuario
                    
                End If
            Else
                Label2.Visible = True
                txterror.Visible = True
                txterror.Text = txterror.Text + vbctrf + "Error, Lnea" & List3.List(i) & "Nombre de identificador invalido" & List10.List(i) + vbNewLine

                i = i + 1
                GoTo inicio
            End If
            
        'SEGUNDO CASO REALES

        Case "float":
            
inicio3:
            i = i + 1
            Var = iden(List10.List(i))
            If (Var = True) Then
                i = i + 1
                If List10.List(i) = ";" Then
                    afloat(v) = List10.List(i - 1)
                    List5.List(v) = afloat(v)
                    v = v + 1
                    GoTo inicio
                End If
                If List10.List(i) = "=" Then
                    i = i + 1
                    If IsNumeric(List10.List(i)) Then
                        i = i + 1
                        If List10.List(i) = ";" Then
                            afloat(v) = List10.List(i - 3)
                            List5.List(v) = afloat(v)
                            v = v + 1
                            GoTo inicio
                        Else
                            If List10.List(i) = "," Then
                                afloat(v) = List10.List(i - 3)
                                List5.List(v) = afloat(v)
                                v = v + 1
                                GoTo inicio3
                            End If
                        End If
                    Else
                        Label2.Visible = True
                        txterror.Visible = True
                        txterror.Text = txterror.Text + vbctrf + "Error, Lnea" & List3.List(i) & "Tipo asignado incorrecto" & List10.List(i) + vbNewLine

                    End If
                End If
                If List10.List(i) = "," Then
                    afloat(v) = List10.List(i - 1)
                    List5.List(v) = afloat(v)
                    v = v + 1
                    GoTo inicio3
                Else
                    Label2.Visible = True
                    txterror.Visible = True
                    txterror.Text = txterror.Text + vbctrf + "Error, Lnea" & List3.List(i) & "Error de sintaxis" & List10.List(i) + vbNewLine

                End If
            Else
                Label2.Visible = True
                txterror.Visible = True
                txterror.Text = txterror.Text + vbctrf + "Error, Lnea" & List3.List(i) & "Nombre de identificador invalido" & List10.List(i) + vbNewLine

                i = i + 1
                GoTo inicio
            End If
            
        'TERCER CASO DOUBLES

        Case "double":
            
inicio4:
            i = i + 1
            Var = iden(List10.List(i))
            If (Var = True) Then
                i = i + 1
                If List10.List(i) = ";" Then
                    adouble(q) = List10.List(i - 1)
                    List6.List(q) = adouble(q)
                    q = q + 1
                    GoTo inicio
                End If
                If List10.List(i) = "=" Then
                    i = i + 1
                    If IsNumeric(List10.List(i)) Then
                        i = i + 1
                        If List10.List(i) = ";" Then
                            adouble(q) = List10.List(i - 3)
                            List6.List(q) = adouble(q)
                            q = q + 1
                            GoTo inicio
                        Else
                            If List10.List(i) = "," Then
                                adouble(q) = List10.List(i - 3)
                                List6.List(q) = adouble(q)
                                q = q + 1
                                GoTo inicio4
                            End If
                        End If
                    Else
                        Label2.Visible = True
                        txterror.Visible = True
                        txterror.Text = txterror.Text + vbctrf + "Error, Lnea" & List3.List(i) & "Tipo asignado incorrecto" & List10.List(i) + vbNewLine

                    End If
                End If
                If List10.List(i) = "," Then
                    adouble(q) = List10.List(i - 1)
                    List6.List(q) = adouble(q)
                    q = q + 1
                    GoTo inicio4
                Else
                    Label2.Visible = True
                    txterror.Visible = True
                    txterror.Text = txterror.Text + vbctrf + "Error, Lnea" & List3.List(i) & "Error de sintaxis" & List10.List(i) + vbNewLine

                End If
            Else
                Label2.Visible = True
                txterror.Visible = True
                txterror.Text = txterror.Text + vbctrf + "Error, Lnea" & List3.List(i) & "Nombre de identificador invalido" & List10.List(i) + vbNewLine
                 i = i + 1
                GoTo inicio
            End If
            
        'CUARTO CASO CHAR

        Case "char":
            
inicio5:
            i = i + 1
            Var = iden(List10.List(i))
            If (Var = True) Then
                i = i + 1
                If List10.List(i) = ";" Then
                    achar(z) = List10.List(i - 1)
                    List7.List(z) = achar(z)
                    z = z + 1
                    GoTo inicio
                End If
                If List10.List(i) = "=" Then
                    i = i + 1
                    If Not IsNumeric(List10.List(i)) Then
                        
                        '''''''''''''''''''''''''''''''
                        r = Len(List10.List(i))
                        If r = 3 Then
                            If Mid$(List10.List(i), 1, 1) = Chr(39) And Mid$(List10.List(i), 3, 1) = Chr(39) Then
                                    i = i + 1
                                    If List10.List(i) = ";" Then
                                        achar(z) = List10.List(i - 1)
                                        List7.List(z) = achar(z)
                                        z = z + 1
                                        GoTo inicio
                                    Else
                                        Label2.Visible = True
                                        txterror.Visible = True
                                        txterror.Text = txterror.Text + vbctrf + "Error, Lnea" & List3.List(i) & "Error de sintaxis" & List10.List(i) + vbNewLine

                                    End If
                            Else
                                Label2.Visible = True
                                txterror.Visible = True
                                txterror.Text = txterror.Text + vbctrf + "Error, Lnea" & List3.List(i) & "Debe de ir entre " & Chr(39) & " " & Chr(39) & "  " & List10.List(i) + vbNewLine

                            End If
                        Else
                            Label2.Visible = True
                            txterror.Visible = True
                            txterror.Text = txterror.Text + vbctrf + "Error, Lnea" & List3.List(i) & "Longitud incorrecta (solo un caracter)" & List10.List(i) + vbNewLine

                        End If
                        
                            
                        '''''''''''''''''''''''''''''''
                        
                        
                        i = i + 1
                        If List10.List(i) = ";" Then
                            achar(z) = List10.List(i - 3)
                            List7.List(z) = achar(z)
                            z = z + 1
                            GoTo inicio
                        Else
                            If List10.List(i) = "," Then
                                achar(z) = List10.List(i - 3)
                                List7.List(z) = achar(z)
                                z = z + 1
                                GoTo inicio5
                            End If
                        End If
                    Else
                        Label2.Visible = True
                        txterror.Visible = True
                        txterror.Text = txterror.Text + vbctrf + "Error, Lnea" & List3.List(i) & "Tipo asignado incorrecto" & List10.List(i) + vbNewLine

                    End If
                End If
                If List10.List(i) = "," Then
                    achar(z) = List10.List(i - 1)
                    List7.List(z) = achar(z)
                    z = z + 1
                    GoTo inicio5
                Else
                    Label2.Visible = True
                    txterror.Visible = True
                    txterror.Text = txterror.Text + vbctrf + "Error, Lnea" & List3.List(i) & "Error de sintaxis" & List10.List(i) + vbNewLine

                End If
            Else
                Label2.Visible = True
                txterror.Visible = True
                txterror.Text = txterror.Text + vbctrf + "Error, Lnea" & List3.List(i) & "Nombre de identificador invalido" & List10.List(i) + vbNewLine

                i = i + 1
                GoTo inicio
            End If
            
        'QUINTO CASO STRING

        Case "String":
            
inicio6:
            i = i + 1
            Var = iden(List10.List(i))
            If (Var = True) Then
                i = i + 1
                If List10.List(i) = ";" Then
                    astring(Y) = List10.List(i - 1)
                    List8.List(Y) = astring(Y)
                    Y = Y + 1
                    GoTo inicio
                End If
                If List10.List(i) = "=" Then
                    i = i + 1
                    If Not IsNumeric(List10.List(i)) Then
                        
    
                        '''''''''''''''''''''''''''''''
                        kkk = 1
                        If kkk = 1 Then
                            r = Len(List10.List(i))
                                                
                            If Mid$(List10.List(i), 1, 1) = Chr(34) And Mid$(List10.List(i), r, 1) = Chr(34) Then
                                i = i + 1
                                If List10.List(i) = ";" Then
                                    astring(Y) = List10.List(i - 1)
                                    List8.List(Y) = astring(Y)
                                    Y = Y + 1
                                    GoTo inicio
                                Else
                                    Label2.Visible = True
                                    txterror.Visible = True
                                    txterror.Text = txterror.Text + vbctrf + "Error, Lnea" & List3.List(i) & "Error de sintaxis" & List10.List(i) + vbNewLine

                                End If
                            Else
                                    Label2.Visible = True
                                    txterror.Visible = True
                                    txterror.Text = txterror.Text + vbctrf + "Error, Lnea" & List3.List(i) & "Debe de ir entre " & Chr(34) & " " & Chr(34) & "  " & List10.List(i) + vbNewLine

                            End If
    
                        End If
                                                   
                        '''''''''''''''''''''''''''''''
                                                
                        i = i + 1
                        If List10.List(i) = ";" Then
                            astring(Y) = List10.List(i - 3)
                            List8.List(Y) = astring(Y)
                            Y = Y + 1
                            GoTo inicio
                        Else
                            If List10.List(i) = "," Then
                                astring(Y) = List10.List(i - 3)
                                List8.List(Y) = astring(Y)
                                Y = Y + 1
                                GoTo inicio6
                            End If
                        End If
                    Else
                        Label2.Visible = True
                        txterror.Visible = True
                        txterror.Text = txterror.Text + vbctrf + "Error, Lnea" & List3.List(i) & "Tipo asignado incorrecto" & List10.List(i) + vbNewLine

                    End If
                End If
                If List10.List(i) = "," Then
                    astring(Y) = List10.List(i - 1)
                    List8.List(Y) = astring(Y)
                    Y = Y + 1
                    GoTo inicio6
                Else
                    Label2.Visible = True
                    txterror.Visible = True
                    txterror.Text = txterror.Text + vbctrf + "Error, Lnea" & List3.List(i) & "Error de sintaxis" & List10.List(i) + vbNewLine

                End If
            Else
                Label2.Visible = True
                txterror.Visible = True
                txterror.Text = txterror.Text + vbctrf + "Error, Lnea" & List3.List(i) & "Nombre de identificador invalido" & List10.List(i) + vbNewLine

                i = i + 1
                GoTo inicio
            End If
            
            
            
        
        Case cdouble = True:
        Case csimple = True:
        Case "=":
        Case ";":
        Case "":
        Case " ":
        Case "Chr(13)":
        Case "'":
        Case "=":
        Case "+":
        Case "-":
        Case "*":
        Case "/":
        Case Chr(34):
        

        Case ";":
  
        
        
        'Case "/":
        '  i = i + 1
        ' If List10.List(i) = "*" Then
        '       i = i + 1
        '       Do While (List10.List(i) <> "*" And List10.List(i) <> "" And List10.List(i) <> " ")
        '           i = i + 1
        '       Loop
        '       If List10.List(i) = "" Or List10.List(i) = " " Then
        '           MsgBox "se esperaba */"
        '       Else
        '           i = i + 1
        '
        '           If List10.List(i) = "/" Then
        '           i = i + 1
        '           Else
        '               MsgBox "se esperaba */"
        '           End If
        '       End If
        '   End If
        '   GoTo inicio
            
        
        
        



'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Case Else: Call otro
          Exit Sub
        

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''



End Select


'correccion de errores en el analisis sintactico por parte del usuario
If txterror.Text <> "" Then
aviso = MsgBox("Existen expresiones invalidas", vbCritical, "Error")
correccion = MsgBox("Desea Corregirlos?", vbYesNo, "Correccion")
    If correccion = vbYes Then
    txtarchivo.Enabled = True
    txtarchivo.SetFocus
    End If
End If

Next i



'''''''''''''''''''''''''''''''''''''
' PROCESO DE VARIABLES NO REPETIDAS '
'''''''''''''''''''''''''''''''''''''

tama = List4.ListCount + List5.ListCount + List6.ListCount + List7.ListCount + List8.ListCount
Dim a(100) As String
j = 0
    For g = 0 To List4.ListCount - 1
    a(j) = List4.List(g)
    List9.AddItem a(j)
    j = j + 1
    Next g
     
    For g = 0 To List5.ListCount - 1
    a(j) = List5.List(g)
    List9.AddItem a(j)
    j = j + 1
    Next g
   
    For g = 0 To List6.ListCount - 1
    a(j) = List6.List(g)
    List9.AddItem a(j)
    j = j + 1
    Next g

    For g = 0 To List7.ListCount - 1
    a(j) = List7.List(g)
     List9.AddItem a(j)
    j = j + 1
    Next g
    
    For g = 0 To List8.ListCount - 1
    a(j) = List8.List(g)
    List9.AddItem a(j)
    j = j + 1
    Next g
    
For g = 0 To List9.ListCount - 1
    For p = 0 To List9.ListCount - 1
    If List9.List(g) = List9.List(p) And g <> p Then
    bandera = True
    End If
    Next p
Next g


If bandera = True Then
Call duplicar
End If





End Sub
Function iden(cad As String) As Boolean
m = Len(cad)

chk = False
For k = 65 To 122
'checar ke el primer elemento sea una letra
If (Mid$(cad, 1, 1) = Chr(k)) Then
chk = True
End If


If i = 90 Then 'para saltarse los simbolos
i = 97
End If

Next k

For i = 2 To m
car = Mid$(cad, i, 1)

t = False
For X = 48 To 122


If (car = "") Or (car = "-") Then
t = False
End If


If car = "_" Then
t = True
End If

If car = Chr(X) Then
t = True
End If

If X = 56 Then
X = 64
End If

If X = 90 Then
X = 96
End If


Next X
If t = False Then
chk = False
Exit For
End If

Next i
iden = chk



End Function



Public Sub duplicar()
txterror.Visible = True
Label2.Visible = True
txterror.Text = txterror.Text + vbctrf + "Error......" & List3.List(i) & " variables repetidas :" + vbNewLine

'correccion de errores en el analisis sintactico por parte del usuario
If txterror.Text <> "" Then
aviso = MsgBox("Existen expresiones invalidas", vbCritical, "Error")
correccion = MsgBox("Desea Corregirlos?", vbYesNo, "Correccion")
    If correccion = vbYes Then
    txtarchivo.Enabled = True
    txtarchivo.SetFocus
    End If
End If

End Sub



Function declarado(cad As String) As Boolean

For d = 0 To List4.ListCount - 1
    If cad = List4.List(d) Then
    declarado = True
    Exit Function
    Else
    declarado = False
    End If

Next d

For d = 0 To List5.ListCount - 1
    If cad = List5.List(d) Then
    declarado = True
    Exit Function
    Else
    declarado = False
    End If

Next d

For d = 0 To List6.ListCount - 1
    If cad = List6.List(d) Then
    declarado = True
    Exit Function
    Else
    declarado = False
    End If

Next d

For d = 0 To List7.ListCount - 1
    If cad = List7.List(d) Then
    declarado = True
    Exit Function
    Else
    declarado = False
    End If

Next d

For d = 0 To List8.ListCount - 1
    If cad = List8.List(d) Then
    declarado = True
    Exit Function
    Else
    declarado = False
    End If

Next d

End Function


Function tipo(cad As String) As Integer

For d = 0 To List4.ListCount - 1
    If cad = List4.List(d) Then
    tipo = 1
    End If

Next d

For d = 0 To List5.ListCount - 1
    If cad = List5.List(d) Then
    tipo = 2
    End If

Next d

For d = 0 To List6.ListCount - 1
    If cad = List6.List(d) Then
    tipo = 3
    End If

Next d

For d = 0 To List7.ListCount - 1
    If cad = List7.List(d) Then
    tipo = 4
    End If

Next d

For d = 0 To List8.ListCount - 1
    If cad = List8.List(d) Then
    tipo = 5
    End If

Next d

'correccion de errores en el analisis sintactico por parte del usuario
If txterror.Text <> "" Then
aviso = MsgBox("Existen expresiones invalidas", vbCritical, "Error")
correccion = MsgBox("Desea Corregirlos?", vbYesNo, "Correccion")
    If correccion = vbYes Then
    txtarchivo.Enabled = True
    txtarchivo.SetFocus
    End If
End If

End Function

Public Sub otro()
       varn = ""
For i = 0 To List11.ListCount

Select Case List11.List(i)

Case "(":
If List11.List(i - 1) = "=" Or List11.List(i - 1) = "+" Or List11.List(i - 1) = "-" Or List11.List(i - 1) = "*" Or List11.List(i - 1) = "/" Then
Else
    txterror.Visible = True
    Label2.Visible = True
    txterror.Text = txterror.Text + vbctrf + "Expresin Incorrecta:" & List11.List(i + 1) + vbNewLine
    'varn = List11.List(i - 1)
    End If

If (declarado(List11.List(i + 1))) = False Then

    If (IsNumeric(Val(List11.List(i + 1)))) = True Then
    Else
    txterror.Visible = True
    Label2.Visible = True
    txterror.Text = txterror.Text + vbctrf + "Asignacin: Variable no declarada :" & List11.List(i + 1) + vbNewLine

    End If
End If


Case ")":
If List11.List(i + 1) = "=" Or List11.List(i + 1) = "+" Or List11.List(i + 1) = "-" Or List11.List(i + 1) = "*" Or List11.List(i + 1) = "/" Then
Else
    txterror.Visible = True
    Label2.Visible = True
    txterror.Text = txterror.Text + vbctrf + "Expresin Incorrecta:" & List11.List(i + 1) + vbNewLine
    End If

If (declarado(List11.List(i - 1))) = False Then

    If (IsNumeric(Val(List11.List(i - 1)))) = True Then
    Else
    txterror.Visible = True
    Label2.Visible = True
    txterror.Text = txterror.Text + vbctrf + "Asignacin: Variable no declarada :" & List11.List(i + 1) + vbNewLine
    End If
End If


Case "=", "*", "+", "-", "/":
If List11.List(i + 1) <> "(" And List11.List(i + 1) <> ")" Then
If List11.List(i + 1) = "" Or List11.List(i + 1) = ";" Then
txterror.Visible = True
Label2.Visible = True
txterror.Text = txterror.Text + vbctrf + "Expresin Incorrecta:" & List11.List(i + 1) + vbNewLine
End If
End If

If List11.List(i + 1) <> "(" And List11.List(i + 1) <> ")" Or List11.List(i + 1) <> ";" Then
If (declarado(List11.List(i - 1))) = False Then

If (IsNumeric(List11.List(i - 1))) = True Then
Else
 
txterror.Visible = True
Label2.Visible = True
txterror.Text = txterror.Text + vbctrf + "Asignacin: Variable no declarada " & List11.List(i - 1) + vbNewLine
    End If
End If
End If


If List11.List(i + 1) <> "(" Then
If (declarado(List11.List(i + 1))) = False Then

    If (IsNumeric(List11.List(i + 1))) = True Then
    
    Else
       
    txterror.Visible = True
    Label2.Visible = True
    txterror.Text = txterror.Text + vbctrf + "Asignacin: Variable no declarada :" & List11.List(i + 1) + vbNewLine

    End If
End If
End If
Case ";":
If List11.List(i - 1) = "+" Or List11.List(i - 1) = "-" Or List11.List(i - 1) = "*" Or List11.List(i - 1) = "/" Then
    txterror.Visible = True
    Label2.Visible = True
    txterror.Text = txterror.Text + vbctrf + "Expresin incorrecta..." & List11.List(i + 1) + vbNewLine

End If
Case "":
Case Else:

End Select
Next i


'correccion de errores en el analisis sintactico por parte del usuario
If txterror.Text <> "" Then
aviso = MsgBox("Existen expresiones invalidas", vbCritical, "Error")
correccion = MsgBox("Desea Corregirlos?", vbYesNo, "Correccion")
    If correccion = vbYes Then
    txtarchivo.Enabled = True
    txtarchivo.SetFocus
    End If
End If



End Sub

